//角色类

module game {
    export class Player {
        id: number
        name: string
        basicInfo: BasicInfo
        equipments: Equipments
        bag: Package
        store: Package
        fightAttri: FightAttri
        viewDisplay: DisplayComponent
        petHouse: Pet[]
        battlePets: Pet[]
        buildings: Buildings
        mapInfo: MapInfo
        workbenches: Workbenches
        supplyBar: ItemComponent[]
        fuse: Fuse
        development: Development
        farmLand: FarmLand
        weather: Weather
        season: number
        tasks: Task[]
        completeTasks: any[]
        public constructor(opts) {
            this.id = opts.id || []
            this.name = opts.name || templateConfig.character[this.id].name
            this.basicInfo = opts.basicInfo ? new BasicInfo(opts.basicInfo) : new BasicInfo({})
            this.equipments = opts.equipments ? new Equipments(opts.equipments) : new Equipments({})
            this.bag = opts.bag || null
            this.store = opts.store || null
            this.fightAttri = new FightAttri({})
            this.viewDisplay = opts.viewDisplay ? new DisplayComponent(opts.viewDisplay) : new DisplayComponent({})
            this.petHouse = opts.petHouse || []
            this.battlePets = opts.battlePets || []
            this.buildings = opts.buildings ? new Buildings(opts.buildings) : new Buildings({})
            this.mapInfo = opts.mapInfo ? new MapInfo(opts.mapInfo) : new MapInfo({})
            this.workbenches = opts.workbenches ? new Workbenches(opts.workbenches) : new Workbenches({})
            this.supplyBar = opts.supplyBar || []
            this.fuse = opts.fuse ? new Fuse(opts.fuse) : new Fuse({}) //融合
            this.development = opts.development ? new Development(opts.development) : new Development({})
            this.farmLand = opts.farmLand ? new FarmLand(opts.farmLand) : new FarmLand({})
            this.weather = opts.weather ? new Weather(opts.weather) : new Weather({})
            this.season = opts.season || 0 //1春天 2夏天 3秋天 4冬天
            this.tasks = opts.tasks || [] //接受的任务
            this.completeTasks = opts.completeTasks || [] //完成的任务
        }
        
        //初始化角色
        initPlayer = function() {
            this.bag = new Package(this.bag)
            this.store = new Package(this.store)
            this.calcAttri()
        }

        //计算人物属性
        calcAttri = function() {
            this.fightAttri = new FightAttri({})
            this.calcBasicInfo()
            this.calcBasicAttri() //人物基础属性
            this.calcEquipment() //装备
            this.calcSkill() //计算技能
            this.calcLvlAttri() //计算等级加成属性
            this.fightAttri.hp = this.fightAttri.maxHp
            this.fightAttri.name = this.name
        }

        calcBasicInfo = function() {
            var basicInfoConfig = templateConfig.character[this.id].basicInfo
        }

        //计算基础属性
        calcBasicAttri = function() {
            var fightAttri: FightAttri = this.fightAttri
            var basicAttri = templateConfig.character[this.id].basicAttri
            fightAttri.attack += basicAttri.attack //攻击力
            fightAttri.maxHp += basicAttri.maxHp //生命
            fightAttri.defend += basicAttri.defend //防御
            fightAttri.crit += basicAttri.crit //暴击概率
            fightAttri.critHurt += basicAttri.critHurt //暴击伤害
            fightAttri.toughness += basicAttri.toughness //韧性
            fightAttri.hit += basicAttri.hit //命中
            fightAttri.dodge += basicAttri.dodge //闪避
        };
        //计算人物穿戴的装备属性
        calcEquipment = function() { };
        //计算技能
        calcSkill = function() {
            for(var i in this.battlePets) {
                var pet: Pet = this.battlePets[i]
                var petId = pet.id
                var skillId = templateConfig.pet[petId].skillId
                this.fightAttri.skills.push(skillId)
            }
        }
        //计算等级加成属性
        calcLvlAttri = function() { };
    }
    
    //角色基础信息
    export class BasicInfo {
        money: number
        gold: number
        lvl: number
        exp: number
        energy: number
        time: number
        public constructor(opts) {
            this.money = opts.money || 0 //当前金钱
            this.gold = opts.gold || 0 //金币
            this.lvl = opts.lvl || 1 //等级
            this.exp = opts.exp || 0 //当前经验
            this.energy = opts.energy || 20 //精力
            this.time = opts.time || 0 //时间 每15分钟加1 4为一个小时 4*24为一天
        }
    }
    
    export class Task {
        taskId: number
        com: number[]
        public constructor(opts){
            this.taskId = opts.taskId 
            this.com = opts.com || []
        }
    }
    class Development {
        lvl: number
        public constructor(opts) {
            this.lvl = 0
        }
    }

    class Developments {
        d: Development[]
        public constructor(opts) {
            this.d = opts.d || []
        }
    }

    class Fuse {
        items: any
        startTime: number
        getItemId: number
        public constructor(opts) {
            this.items = opts.items || []
            this.startTime = opts.startTime || 0
            this.getItemId = opts.getItemId || 0
        }
    }

    class Build {
        lvl: number
        completeTime: number
        public constructor() {
            this.lvl = 0
            this.completeTime = 0
        }
    }
    class Buildings {
        petHouseBuild: Build
        smithyBuild: Build
        storeBuild: Build
        museumBuild: Build
        arsenalBuild: Build
        workerBuild: Build
        farmlandBuild: Build
        landscapeBuild: Build
        trainBuild: Build
        public constructor(opts) {
            this.petHouseBuild = opts.petHouseBuild || new Build()
            this.smithyBuild = opts.smithyBuild || new Build()
            this.storeBuild = opts.storeBuild || new Build()
            this.museumBuild = opts.museumBuild || new Build()
            this.arsenalBuild = opts.arsenalBuild || new Build()
            this.workerBuild = opts.workerBuild || new Build()
            this.farmlandBuild = opts.farmlandBuild || new Build()
            this.landscapeBuild = opts.landscapeBuild || new Build()
            this.trainBuild = opts.trainBuild || new Build()
        }
    }
    //地图信息
    export class MapInfo {
        mapId: number
        layerId: number
        mapLayerInfo: number
        public constructor(opts) {
            this.mapId = opts.mapId || 420001
            this.layerId = opts.layerId || 0
            this.mapLayerInfo = opts.mapLayerInfo || 0
        }
    }

    //工作台
    export class Workbenches {
        smithy: any[]
        pet: any[]
        public constructor(opts) {
            this.smithy = opts.smithy || []
            this.pet = opts.pet || []
        }
    }
    
    //装备
    export class Equipment {
        id: number
        lvl: number
        stack: number
        public constructor(opts) {
            this.id = opts.id
            this.lvl = opts.lvl || 0
            this.stack = 1
        }
    }

    export class Equipments {
        weapon: Equipment
        body: Equipment
        head: Equipment
        foot: Equipment
        decoration: Equipment
        public constructor(opts) {
            this.weapon = opts.weapon || 0
            this.body = opts.body || 0
            this.head = opts.head || 0
            this.foot = opts.foot || 0
            this.decoration = opts.decoration || 0
        }
    }
    //农田的每个格子
    export class Land {
        itemId: number
        startTime: number
        value: number
        public constructor(opts: any) {
            this.itemId = opts.itemId || 0
            this.startTime = opts.startTime || 0
            this.value = opts.value || 100
        }
    }
    //农田
    export class FarmLand {
        num: number
        lands: Land[]
        public constructor(opts) {
            this.num = opts.num || 6
            this.lands = opts.lands || []
        }
    }
    //天气
    export class Weather {
        flashTime: number //下次刷新时间
        index: number  //1晴天、2下雨 3阴天 4雷雨 5下雪（冬季）6沙暴
        public constructor(opts){
            this.flashTime = opts.flashTime || 0
            this.index = opts.index || 0
        }
    }
    
}
